# Global Defines
#ROOT_DIR = `pwd`
ROOT_DIR = $(shell pwd)

INSTALL_DIR = $(ROOT_DIR)/lib

STATIC_LINK=y

ifeq ($(STATIC_LINK),y)
LIBNAME     = libdpl.a
else
LIBNAME     = libdpl.so
endif

# Target
TARGETS_lib = $(ROOT_DIR)/$(LIBNAME)
all:$(TARGETS_lib)

# make the build silent
V =

ifeq ($(strip $(V)),)
	E = @echo
	Q = @
else
	E = @\#
	Q =	
endif
export E Q


# SRCS
SRC_DIR := $(ROOT_DIR)/dpl
OBJ_DIR := $(ROOT_DIR)/objs

SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(patsubst %.c, %.o, $(SRCS))))
#SRCS := $(wildcard $(PWD)/dpl/*.c)
#OBJS := $(addprefix $(PWD)/objs/, $(notdir $(patsubst %.c, %.o, $(SRCS))))




#OBJS+=$(TARGETS_OBJS)

BUILD_DATE:=$(shell date)

# Tools
LD      := ld
CC      := gcc
CXX     := g++
AR      := ar
STRIP   := strip
NM      := nm
CP		:= cp
MV		:= mv
RANLIB	:= ranlib
#include $(PROJECT_ROOT)/build/rules.mk

# Defines
DEFINES +=	\
	-DDPL  
# Includes
INCLUDEDIRS = -I. \
			-I$(ROOT_DIR)/dpl \
			
			
			
# CFlags	

ifeq ($(STATIC_LINK),y)
CFLAGS = \
			
else
CFLAGS =	\
		-fPIC	\
		-shared	
		
endif
		
CFLAGS += $(DEFINES) $(INCLUDEDIRS)

# LDFlags
LDFLAGS = \
	#-L$(CSVT_DIR)/lib

# AR flags
ARFLAGS = rcs

# LIBS
LIBS = -lstdc++  -lpthread -lm -lrt -lc -ldl -lcrypt


# Build rules
##############################################################################
#.SILENT:

.PHONY: clean build_info dpl all

	
build_info:
	@echo "const static char *build_date = \"`date`\";" > build_info.h

# Build application if specified, link this object with local libs
$(TARGETS_lib): build_info $(OBJS) $(CXXOBJS)
ifeq ($(STATIC_LINK),y)
	$(E) "Creating static lib $(TARGETS_lib) ..."
	$(Q) $(RM) $@
	$(Q) $(AR) $(ARFLAGS) $@ $(OBJS)
	$(Q) $(RANLIB) $@
else
	$(E) "Creating dynamic $(TARGETS_lib) ..."
	$(RM) $(TARGETS_lib)* 
	$(CC) $(OBJS) $(LIBS) $(CXXOBJS) $(LDFLAGS) $(CFLAGS) -o $@
endif

# Just generate the obj file , for testing
obj: build_info $(OBJS)
	$(E) "Creating the OBJ file finished"


# Compilation target for C files
$(OBJ_DIR)/%.o:$(SRC_DIR)/%.c 
	$(E) "Compiling SRC$< ..."
	$(CC) -c $(CFLAGS) -o $@ $<

clean:
	$(E) Cleaning $(TARGETS_lib)
	$(Q) $(RM) $(OBJS) $(patsubst %.o, %.d, $(OBJS)) $(TARGETS_lib)
